<template>
  <div class="list_in">
    <div class="listr_in_top tanxin">
        <div class="photo">
          <img 
            :src="playList.coverImgUrl"
            alt=""
            width="150px"
            height="150px"
          />
        </div>
        <div class="info">
          <p class="p1">{{ playList.name }}</p>
          <div class="user">
            <i class="icn" style="overflow: hidden"></i>
            <span class="sep">最近更新: {{ createTime | showDate }}</span>
            <span class="fc">（{{ update }}）</span>
          </div>
          <!-- 底部按钮 -->
          <div class="btns">
            <a class="play" title="播放" @click="play">
              <i class="play_in">
                <span>播放</span>
              </i>
            </a>
            <a class="add" title="添加到播发列表"></a>
            <a class="dis" title="收藏">
              <span>({{ collect || '收藏' }})</span>
            </a>
            <a class="share" title="分享">
              <span>({{ share || '分享' }})</span>
            </a>
            <a class="download">
              <span>下载</span>
            </a>
            <a class="comment" title="评论" @click="viewClick()">
              <span>({{ comment || '评论' }})</span>
            </a>
          </div>
        </div>
    </div>
    <div class="listr_in_index">
      <div class="titles">
        <h3>歌曲列表</h3>
        <span class="sub">{{ length }}首歌</span>
        <div class="more">
          播放：<span class="fc">{{ playCount }} </span>次
        </div>
      </div>
      <div class="song">
        <div class="header">
          <li class="w1"></li>
          <li class="w2">标题</li>
          <li class="w3">时长</li>
          <li class="w4">歌手</li>
        </div>
        <div class="mainer">
          <ul v-for="(item, index) in biaosheng" :key="index" class="lists">
            <li class="m1 ellipsis">
              <span>{{ index + 1 }}</span>
            </li>
            <li class="m2">
              <img :src="item.al.picUrl" v-show="index >= 0" />
              <i class="play" @click="playmusic(index)" v-show="item.resourceState"></i>
              <i class="active" v-show="!item.resourceState"></i>
              <span :title="item.name" class="handle ellipsis" @click="$router.push(`/songlist/${item.id}`)">{{ item.name }}</span>
              <i class="mv" v-show="item.mv" @click="$router.push(`/mvlist/${item.mv}`)"></i>
            </li>
            <li class="m3">
              <span class="time">{{ min(item) }}:{{ sec(item) }}</span>
              <div class="show">
                <a text="添加到播放列表" class="a1"></a>
                <a text="收藏" class="a2"></a>
                <a text="分享" class="a3"></a>
                <a text="下载" class="a4"></a>
              </div>
            </li>
            <li class="m4 ellipsis">
              <a :title="item1.name" class="artist" v-for="item1 in item.ar" :key="item1.id" @click="$router.push(`/artlist/${item1.id}`)">{{ item1.name }}<span>/</span></a>
            </li>
          </ul>
        </div>
      </div>
    </div>
    <MusicPlay :ids="ids" :imgUrl="imgUrl" :isPlay="isPlay" />
  </div>
</template>

<script>
import { reqPlayList, reqAllList } from "@/request/api";
import { formatDate } from '@/assets/utils/date';
import MusicPlay from "@/components/MusicPlay.vue";
export default {
  data() {
    return {
      playList: "",
      love: "",
      createTime: 0,
      collect: 0,
      share: 0,
      comment: 0,
      length: 0,
      playCount: 0,
      biaosheng: [],
      // ids值不唯一
      // ids: 1988565273,
      ids: 0,
      imgUrl: "https://img2.baidu.com/it/u=1611088966,2458167776&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500",
      isPlay: false,
    };
  },
  components: {
    MusicPlay,
  },
  filters: {
    showDate: function(value) {
      let date = new Date(value);
      // return formatDate(date, 'yyyy-MM-dd hh:mm:ss');
      return formatDate(date, 'yyyy-MM-dd');
    }
  },
  computed: {
    id() {
      if (this.$route.query.id == undefined) return "19723756";
      return this.$route.query.id;
    },
    update() {
      if (this.$route.query.update == undefined) return "刚刚更新";
      return this.$route.query.update;
    }
  },
  created() {
    // 根据id获取 歌曲数量 和 歌曲播发次数
    reqPlayList(this.id).then((res) => {
      // console.log(res);
      this.playList = res.data.playlist;
      this.createTime = res.data.playlist.trackUpdateTime;
      this.collect = res.data.playlist.subscribedCount;
      this.share = res.data.playlist.shareCount;
      this.comment = res.data.playlist.commentCount;
      this.biaosheng = res.data.playlist.tracks;
      this.length = res.data.playlist.trackCount;
      this.playCount = res.data.playlist.playCount;
    });
    // 根据id获取 歌曲列表数据
    reqAllList(this.id).then((res) => {
      // console.log(res);
      this.biaosheng = res.data.songs;
    });
  },
  methods: {
    viewClick() {
      document.querySelector('#view').scrollIntoView({
        behavior: "auto",
        block: "center",
        inline: "nearest"
      })
    },
    min(song) {
      if (parseInt(song.dt / 60000) < 10)
        return "0" + parseInt(song.dt / 60000);
      else return parseInt(song.dt / 60000);
    },
    sec(song) {
      let x = parseInt(song.dt / 60000);
      let y = parseInt(song.dt / 1000 - x * 60);
      if (y < 10) return "0" + y;
      else return y;
    },
    play() {
      this.biaosheng.forEach(item=>item.resourceState=true);
      this.biaosheng[0].resourceState = false;
      this.ids = this.biaosheng[0].id;
      this.imgUrl = this.biaosheng[0].al.picUrl;
      this.isPlay = true;
    },
    playmusic(index) {
      this.biaosheng.forEach(item=>item.resourceState=true);
      this.biaosheng[index].resourceState = false;
      this.ids = this.biaosheng[index].id;
      this.imgUrl = this.biaosheng[index].al.picUrl;
      this.isPlay = true;
    },
  },
};
</script>
 
<style lang = "less" scoped>
@import "../../assets/base";
.listr_in_top {
    height: 240px;
    .info {
      width: 480px;
      height: 150px;
      margin: 50px 50px 0 0;
      padding: 20px;
      box-sizing: border-box;
      .p1 {
        font-size: 20px;
        color: #333;
      }
      .user {
        margin-top: 5px;
        width: 100%;
        height: 35px;
        line-height: 35px;
        margin-bottom: 20px;
        font-size: 12px;
        i {
          display: inline-block;
          width: 13px;
          height: 13px;
          position: relative;
          top: 2px;
          margin-left: 3px;
          background: url("../../assets/images/public/icon.png") no-repeat -18px -682px;
        }
        .sep {
          color: #666;
          margin-right: 10px;
          margin-left: 5px;
        }
        .fc {
          color: #999;
        }
      }
      .btns {
        height: 31px;
        display: flex;
        .play {
          span {
            font-size: 12px;
            color: #fff;
            line-height: 31px;
            padding: 0 0 0 35px;
          }
          .play_in {
            width: 65px;
            height: 31px;
            display: block;
            background: url("../../assets/images/public/button2.png") no-repeat;
            background-position: 0 -633px;
            &:hover {
              cursor: pointer;
              background-position: 0 -719px;
            }
          }
        }
        .add {
          width: 31px;
          height: 31px;
          margin-right: 5px;
          background: url("../../assets/images/public/button2.png") no-repeat 0 -1588px;
          &:hover {
            cursor: pointer;
            background-position: -40px -1588px;
          }
          &:active {
            background-position: -80px -1588px;
          }
        }
        .dis {
          margin-right: 6px;
          height: 100%;
          background: url("../../assets/images/public/button2.png") no-repeat;
          background-position: 0px -1063px;
          span {
            display: inline-block;
            height: 100%;
            background: url("../../assets/images/public/button2.png") no-repeat right -1020px;
            line-height: 30px;
            padding-left: 30px;
            padding-right: 4px;
            font-size: 12px;
            // color: #ccc;
          }
          &:hover {
            color: #666;
            cursor: pointer;
          }
        }
        .share {
          height: 31px;
          margin-right: 6px;
          float: left;
          min-width: 23px;
          cursor: pointer;
          background: url("../../assets/images/public/button2.png") no-repeat;
          background-position: 0 -1225px;
          span {
            height: 100%;
            display: inline-block;
            line-height: 30px;
            padding-left: 28px;
            padding-right: 4px;
            background: url("../../assets/images/public/button2.png") no-repeat;
            background-position: right -1020px;
            font-size: 12px;
          }
          &:hover {
            color: #666;
            cursor: pointer;
          }
        }
        .download {
          margin-right: 5px;
          height: 31px;
          min-width: 23px;
          cursor: pointer;
          background: url("../../assets/images/public/button2.png") no-repeat;
          background-position: 0 -2761px;
          span {
            height: 100%;
            display: inline-block;
            line-height: 30px;
            padding-left: 28px;
            padding-right: 8px;
            background: url("../../assets/images/public/button2.png") no-repeat;
            background-position: right -1020px;
            font-size: 12px;
          }
          &:hover {
            color: #666;
            cursor: pointer;
          }
        }
        .comment {
          margin-right: 5px;
          height: 31px;
          min-width: 23px;
          cursor: pointer;
          background: url("../../assets/images/public/button2.png") no-repeat;
          background-position: 0 -1465px;
          span {
            height: 100%;
            display: inline-block;
            line-height: 30px;
            padding-left: 28px;
            padding-right: 8px;
            background: url("../../assets/images/public/button2.png") no-repeat;
            background-position: right -1020px;
            font-size: 12px;
          }
          &:hover {
            color: #666;
            cursor: pointer;
          }
        }
      }
  }
  .photo {
    width: 150px;
    height: 150px;
    margin-left: 50px;
    margin-top: 50px;
  }
}
.listr_in_index {
  width: 670px;
  min-height: 400px;
  margin: 0 auto;
  .titles {
    width: 100%;
    height: 35px;
    border-bottom: 2px solid @red;
    h3 {
      font-family: "Microsoft Yahei", Arial, Helvetica, sans-serif;
      font-size: 20px;
      line-height: 28px;
      font-weight: normal;
      color: #333;
      float: left;
    }
    .sub {
      margin: 9px 0 0 20px;
      float: left;
      color: #666;
      font-size: 12px;
      font-family: Arial, Helvetica, sans-serif;
      -webkit-text-size-adjust: none;
    }
    .more {
      margin-top: 5px;
      height: 16px;
      float: right;
      font-size: 12px;
      .fc {
        color: @red;
        font-weight: bold;
      }
    }
  }
  .song {
    width: 100%;
    border: 1px solid #d9d9d9;
    .header {
      width: 100%;
      height: 39px;
      display: flex;
      font-size: 12px;
      color: #666;
      li {
        border-right: 1px solid #d9d9d9;
        background-image: linear-gradient(
          rgb(255, 255, 255),
          rgb(240, 240, 240)
        );
        padding: 8px 10px;
        box-shadow: 0 1px 1px 1px rgba(0, 0, 0, 0.1);
        line-height: 26px;
      }
      .w1 {
        width: 77px;
      }
      .w2 {
        width: 326px;
      }
      .w3 {
        width: 91px;
      }
      .w4 {
        width: 174px;
      }
    }
    .mainer {
      width: 100%;
      display: block;
      font-size: 12px;
      a {
        color: #000;
        text-decoration: none;
      }
      ul:nth-of-type(even) {
        background: #e5e5e5;
      }
      ul:nth-of-type(odd) {
        background: #f6f6f6;
      }
      .good {
        height: 66px;
        span,
        a,
        i {
          display: block;
          margin-top: 20px !important;
          font-size: 12px;
        }
      }
      ul {
        height: 30px;
        width: 100%;
        display: flex;
        // &:nth-child(-n + 3) {
        //   height: 80px;
        //   align-items: center;
        // }
        &:hover .time {
          display: none !important;
        }
        &:hover .show {
          display: block !important;
        }

        li {
          padding: 6px 10px;
        }
        .m1 {
          width: 70px;
          padding: 6px 10px;
          line-height: 18px;
          span {
            float: left;
            width: 25px;
            height: 18px;
            color: #999;
            text-align: center;
          }
          i {
            margin: 0 8px;
            float: left;
            width: 16px;
            height: 17px;
            background: url("../../assets/images/public/icon.png") no-repeat -67px -283px;
          }
        }
        .m2 {
          width: 326px;
          display: flex;
          align-items: center;
          .handle{
            width: 200px;
            cursor: pointer;
          }
          img {
            float: left;
            margin-right: 10px;
            height: 20px;
            margin-top: 3px;
          }
          .play {
            float: left;
            display: block;
            width: 17px;
            height: 17px;
            margin-right: 8px;
            background: url("../../assets/images/public/table.png") no-repeat -0px -103px;

            &:hover {
              background-position: -0px -128px;
              cursor: pointer;
            }
          }
          .active {
            float: left;
            display: block;
            width: 17px;
            height: 17px;
            margin-right: 8px;
            background: url("../../assets/images/public/table.png") no-repeat -20px -128px;
          }
          .mv {
            float: left;
            display: block;
            width: 23px;
            height: 17px;
            background: url("../../assets/images/public/table.png") no-repeat;
            background-position: 0 -151px;
            &:hover {
              background-position: -30px -151px;
              cursor: pointer;
            }
          }
          a {
            width: 200px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            float: left;
            &:hover {
              color: #666;
              cursor: pointer;
              text-decoration: underline;
            }
          }
        }
        .m3 {
          width: 91px;
          .time {
            display: block;
          }
          .show {
            width: 79px;
            height: 18px;
            display: none;
            a {
              margin: 2px 0 0 4px;
              width: 18px;
              height: 16px;
              display: block;
              float: left;
              background: url("../../assets/images/public/table.png") no-repeat;
              &:hover {
                cursor: pointer;
              }
            }
            .a1 {
              width: 13px;
              height: 13px;
              margin-top: 2px;
              margin-left: 0;
              background: url("../../assets/images/public/icon.png") no-repeat;
              background-position: 0 -700px;

              &:hover {
                background-position: -22px -700px;
              }
            }
            .a2 {
              background-position: 0 -174px;
              &:hover {
                background-position: -20px -174px;
              }
            }
            .a3 {
              background-position: 0 -195px;
              &:hover {
                background-position: -20px -195px;
              }
            }
            .a4 {
              background-position: -81px -174px;
              &:hover {
                background-position: -104px -174px;
              }
            }
          }
        }
        .m4 {
          width: 173px;
          color: #333;
          & a:hover {
            color: #666;
            cursor: pointer;
            text-decoration: underline;
          }
          .artist {
            &:last-child {
              span {
                display: none;
              }
            }
          }
        }
      }
    }
  }
}
</style>